package com.bsj.power.pls.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.def.vo.pls.watch.*;
import com.bsj.power.pls.service.KeepWatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : zhuojie.c
 * @version V1.0
 * @Description: TODO
 * @date Date : 2024年08月28日
 * @menu 巡更模块
 */
@RestController
@RequestMapping("/keepWatch")
//@RequestMapping("/pls/keepWatch")
public class KeepWatchController {

    @Autowired
    private KeepWatchService keepWatchService;


    /**
     * 新增巡更任务
     *
     * @param keepWatchAddVO
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody IKeepWatchAddVO keepWatchAddVO) {
        return keepWatchService.add(keepWatchAddVO);
    }

    /**
     * 更新巡更任务
     *
     * @param keepWatchUpdateVO
     * @return
     */
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody IKeepWatchUpdateVO keepWatchUpdateVO) {
        return keepWatchService.update(keepWatchUpdateVO);
    }

    /**
     * 更改巡更任务状态
     *
     * @param watchChangeStatusVO
     * @return
     */
    @PostMapping("/changeStatus")
    public JsonResult changeStatus(@Validated @RequestBody IWatchChangeStatusVO watchChangeStatusVO) {
        return keepWatchService.changeStatus(watchChangeStatusVO);
    }

    /**
     * 删除巡更任务
     *
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public JsonResult delete(Long id) {
        if (id == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return keepWatchService.delete(id);
    }

    /**
     * 巡更任务列表
     *
     * @param keepWatchSearchVO
     * @return
     */
    @GetMapping("/page")
    public JsonResult<List<OKeepWatchPageVO>> page(IKeepWatchSearchVO keepWatchSearchVO) {
        return keepWatchService.page(keepWatchSearchVO);
    }

    /**
     * 巡更任务详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public JsonResult<OKeepWatchDetail> detail(Long id) {
        if (id == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return keepWatchService.detail(id);
    }

    /**
     * 计算达标，到达率
     * @param id
     * @return
     */
    @GetMapping("/reachPos")
    public JsonResult reachPos(Long id) {
        if (id == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return keepWatchService.reachPos(id);
    }
}
